package LeetCode.leetcode209;

public class Review4 {
    public int minSubArrayLen(int target, int[] nums) {
        int l = 0, r = 0, sum = 0, result = Integer.MAX_VALUE;
        while (r < nums.length) {
            sum += nums[r];
            while (sum >= target) {
                result = Math.min(result, r - l + 1);
                sum -= nums[l++];
            }
            r++;
        }
        return result == Integer.MAX_VALUE ? 0 : result;
    }
}
